/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (nums, target) {
    let map = {};
    for (let i = 0; i < nums.length; i++) {
        const key = target - nums[i];
        if (map[key] !== undefined) {
            return [map[key], i];
        }
        map[nums[i]] = i;
    }
    return [];
};
console.log(twoSum([2, 7, 11, 15],9));